<template>
  <div class="app-container">
    <el-form ref="form" :model="list" label-width="120px">
      <el-form-item label="ID" hidden="hidden">
        <el-input v-model="list.id" />
      </el-form-item>
      <el-form-item label="工作ID">
        <el-input v-model="list.workId" />
      </el-form-item>
      <el-form-item label="周次">
        <el-input v-model="list.weekly" />
      </el-form-item>

      <el-form-item label="工作时间">
        <div class="block">
          <el-date-picker
            v-model="list.workTime"
            type="datetime"
            placeholder="选择日期时间"
          />
        </div></el-form-item>

      <el-form-item label="星期">
        <el-input v-model="list.week" />
      </el-form-item>
      <el-form-item label="用户名">
        <el-input v-model="list.userName" />
      </el-form-item>
      <el-form-item label="工作内容">
        <el-input v-model="list.workContent" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">确定</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import qs from 'qs'

export default {
  data() {
    return {
      list: {
      }
    }
  },
  created() {
    this.fatchDataById()
  },
  methods: {
    fatchDataById() {
      var _this = this
      var id = this.$route.params.id
      this.$axios.get('/work/getWorkById?id=' + id)
        .then(function(res) {
          _this.list = res.data
        })
    },
    onSubmit() {
      this.$axios.put(`/work/updateWork`, qs.stringify({
        'id': this.list.id,
        'workId': this.list.workId,
        'weekly': this.list.weekly,
        'workTime': this.list.workTime,
        'week': this.list.week,
        'userName': this.list.userName,
        'workContent': this.list.workContent
      }), {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
      })
        .then(res => {
          this.$message({
            message: '操作成功！',
            type: 'success'
          })
          this.$router.push('/work/workList')
        })
    },
    onCancel() {
      this.$message({
        message: '取消成功！',
        type: 'warning'
      })
      this.$router.push('/work/workList')
    }
  }
}
</script>

